
package com.softa.common.service.impl;

import com.softa.common.dao.SysRoleresMapper;
import com.softa.common.entity.SysRoleres;
import com.softa.common.service.RoleResService;
import com.softa.common.sysconfig.support.DataTableRequest;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * @author hasee
 */
@Service
public class RoleResServiceImpl implements RoleResService {
	
	@Resource
	private SysRoleresMapper sysRoleresMapper;
	

	@Override
	public void saveRoleRes(String resIds, Long roleId) {
		this.deleteRoleResByRoleId(roleId);
		if(resIds!=null && !"".equals(resIds)){
			String[] arr=resIds.split(",");
			SysRoleres r;
			for(String resID:arr){
				r = new SysRoleres();
				r.setResId(Long.parseLong(resID));
				r.setRoleId(roleId);
				sysRoleresMapper.insert(r);
			}
		}
	}

	@Override
	public List<SysRoleres> queryRoleResListByRoleId(Long roleId) {
		DataTableRequest dataGrid = new DataTableRequest();
		dataGrid.getParams().put("roleId", roleId);
		return sysRoleresMapper.selectByCondition(dataGrid);
	}

	@Override
	public Integer deleteRoleResByRoleId(Long roleId) {
		return sysRoleresMapper.deleteRoleResByRoleId(roleId);
	}

}
